package com.yanqu.road.entity.log;

import com.yanqu.road.entity.FieldTypeAnnotation;
import com.yanqu.road.entity.activity.washe.game.WasheRoomData;
import com.yanqu.road.entity.activity.washe.game.WasheUserGameData;
import com.yanqu.road.entity.enums.washe.eWasheLogType;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.Date;

@FieldTypeAnnotation(tableName = "t_n_log_washe_operate")
public class LogWasheOperate {

    protected static Logger logger = LogManager.getLogger(LogWasheOperate.class.getName());

    @FieldTypeAnnotation(desc = "玩家ID")
    private long userId;
    @FieldTypeAnnotation(desc = "对手ID")
    private long opponentUserId;
    @FieldTypeAnnotation(desc = "房间号")
    private long roomId;

    @FieldTypeAnnotation(desc = "操作类型")
    private int type; // eWasheLogType
    @FieldTypeAnnotation(desc = "参数（技能ID、卡片ID、没有就是0）")
    private int param;

    @FieldTypeAnnotation(desc = "时间")
    private Date time;
    @FieldTypeAnnotation(desc = "当前回合")
    private int round;
    @FieldTypeAnnotation(desc = "模式")
    private int modeId;
    @FieldTypeAnnotation(desc = "盘面机制")
    private int sceneId;

    @FieldTypeAnnotation(desc = "操作后剩余步数")
    private int step;
    @FieldTypeAnnotation(desc = "操作后卡片蓝量")
    private int cardMp;
    @FieldTypeAnnotation(desc = "操作后分数")
    private long score;

    public static LogWasheOperate create(WasheRoomData roomData, boolean isPlayer1, eWasheLogType logType, int logParam) {
        if (roomData != null && roomData.getPlayer1() != null && roomData.getPlayer2() != null) {
            try {
                return new LogWasheOperate(roomData, isPlayer1, logType, logParam);
            } catch (Exception e) {
                logger.error("error : ", e);
            }
        }
        return null;
    }

    private LogWasheOperate(WasheRoomData roomData, boolean isPlayer1, eWasheLogType logType, int logParam) {
        WasheUserGameData self = isPlayer1 ? roomData.getPlayer1() : roomData.getPlayer2();
        WasheUserGameData opponent = isPlayer1 ? roomData.getPlayer2() : roomData.getPlayer1();

        userId = self.getUserMatchData().getUserId();
        opponentUserId = opponent.getUserMatchData().getUserId();
        roomId = roomData.getRoomId();

        type = logType.getValue();
        param = logParam;

        time = new Date();
        round = roomData.getRound();
        modeId = roomData.getModeId();
        sceneId = roomData.getGameData() != null ? roomData.getGameData().getSceneId() : -1;

        step = self.getStep();
        cardMp = self.getCard().getCardMp();
        score = self.getScore();
    }

    public long getUserId() {
        return userId;
    }

    public void setUserId(long userId) {
        this.userId = userId;
    }

    public long getOpponentUserId() {
        return opponentUserId;
    }

    public void setOpponentUserId(long opponentUserId) {
        this.opponentUserId = opponentUserId;
    }

    public long getRoomId() {
        return roomId;
    }

    public void setRoomId(long roomId) {
        this.roomId = roomId;
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public Date getTime() {
        return time;
    }

    public void setTime(Date time) {
        this.time = time;
    }

    public int getRound() {
        return round;
    }

    public void setRound(int round) {
        this.round = round;
    }

    public int getModeId() {
        return modeId;
    }

    public void setModeId(int modeId) {
        this.modeId = modeId;
    }

    public int getSceneId() {
        return sceneId;
    }

    public void setSceneId(int sceneId) {
        this.sceneId = sceneId;
    }

    public int getStep() {
        return step;
    }

    public void setStep(int step) {
        this.step = step;
    }

    public int getCardMp() {
        return cardMp;
    }

    public void setCardMp(int cardMp) {
        this.cardMp = cardMp;
    }

    public long getScore() {
        return score;
    }

    public void setScore(long score) {
        this.score = score;
    }

    public int getParam() {
        return param;
    }

    public void setParam(int param) {
        this.param = param;
    }
}
